/**
 * 获取响应计算器函数
 *
 * @param minColumnWidth 最小列宽
 */
export function getResponsiveComputer(minColumnWidth: number) {
  const responsiveSteps = [
    `24 ${minColumnWidth * 2}`,
    `12 ${minColumnWidth * 3}`,
    `8 ${minColumnWidth * 4}`,
    `6 ${minColumnWidth * 6}`,
    `4 ${minColumnWidth * 8}`,
    `3 ${minColumnWidth * 12}`,
    `2 ${minColumnWidth * 24}`,
  ];
  const responsiveSpans = [24, 12, 8, 6, 4, 3, 2];

  return (span: number) => {
    const steps = [];
    for (const [i, responsiveSpan] of responsiveSpans.entries()) {
      if (span < responsiveSpan) {
        steps.push(responsiveSteps[i]);
        continue;
      }

      if (steps.length) {
        steps.push(span);
        return steps.join(':');
      }

      return span;
    }

    return span;
  };
}

/**
 * 计算响应列
 *
 * @param minColumnWidth 最小列宽
 * @param minSpan 最小跨度
 * @returns 响应列配置
 */
export function computeResponsiveColumns(minColumnWidth: number, minSpan = 1) {
  return [
    `${minSpan} ${minColumnWidth * 2}`,
    `${2 * minSpan} ${minColumnWidth * 3}`,
    `${3 * minSpan} ${minColumnWidth * 4}`,
    `${4 * minSpan} ${minColumnWidth * 6}`,
    `${6 * minSpan} ${minColumnWidth * 8}`,
    `${8 * minSpan} ${minColumnWidth * 12}`,
    `${12 * minSpan} ${minColumnWidth * 24}`,
    24 * minSpan,
  ].join(':');
}
